package com.etime.service.impl;

import com.etime.mapper.TicketMapper;
import com.etime.pojo.Order;
import com.etime.service.TicketService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.etime.pojo.Ticket;
import java.util.List;

@Service
public class TicketServiceImpl implements TicketService {
    @Autowired
    private TicketMapper ticketMapper;

    @Override
    public PageInfo<Ticket> getTicketByPage(Integer page) {
        PageHelper.startPage(page,5);
        List<Ticket> list=ticketMapper.getAllTicket();
        PageInfo<Ticket> pageInfo=new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public PageInfo<Ticket> getTicketByNo(Integer page, String train_no) {
        PageHelper.startPage(page,5);
        List<Ticket> list=ticketMapper.getTicketByNo("%"+train_no+"%");
        PageInfo<Ticket> pageInfo=new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public boolean addTicket(Ticket ticket) {
        int rows=ticketMapper.addTicket(ticket);
        if(rows==0){
            return false;
        }else{
            return true;
        }

    }

    @Override
    public Ticket getTicketById(Integer train_id) {
        return ticketMapper.getTicketById(train_id);
    }

    @Override
    public boolean editTicket(Ticket ticket) {
        int rows=ticketMapper.editTicket(ticket);
        if (rows == 0) {
            return false;
        } else {
            return true;
        }
    }

    @Override
    public List<Ticket> getTicketBySth(Ticket ticket) {
        return ticketMapper.getTicketBySth(ticket);
    }

    @Override
    public void editTicketNum(Order order) {
        ticketMapper.editTicketNum(order);
    }


}
